<template>
  <view>
    <form @submit="" @reset="">
      <view class="container">
        <image class="logoImg" src="/static/images/ic_logo.png"></image>
        <button
          class="submit_btn"
          type="primary"
          open-type="getUserInfo"
          @getuserinfo="getUserInfo"
        >
          微信一键登录
        </button>
      </view>
    </form>

    <!-- parse <template is="companyInfo" :data="companyNames"></template> -->
    <block name="companyInfo">
      <view class="companyInfo">
        <text class="companyName">{{ companyNames }}</text>
      </view>
    </block>
  </view>
</template>

<script>
const app = getApp();
let Store = app.globalData.Store;
let Sign = app.globalData.Sign;
let Api = app.globalData.Api;
export default {
  data() {
    return {
      companyNames: '- ' + app.globalData.Appname + ' -'
    };
  }, // 生命周期函数--监听页面加载
  onLoad: function (options) {
    //跳转源页面
    Store.setItem('pay_source', options.pay_source);
  },
  methods: {
    // 用户点击 注册
    getUserInfo(e) {
      if (e.detail.userInfo == undefined) {
        uni.showToast({
          title: '请点击允许授权后登录',
          icon: 'none'
        });
      } else {
        uni.login({
          success: (res) => {
            console.log(res)
            if (res.code) {
              const signObject = {
                code: res.code
              };
              const signvalue = Sign.signutil(signObject);
              app.globalData
                .get(Api.getSession, {
                  code: res.code,
                  sign: signvalue
                })
                .then((re) => {
                  Store.setItem('token', re.token);
                  app.globalData.clickCheckLogin(e);
                })
                .catch((res) => {
                  console.log('error:' + res);
                });
            }
          }
        });
      }
    }
  }
};
</script>
<style>
@import "./sysLogin.css";
</style>
